package com.dv.web.controller.websocket;

import com.dv.common.core.controller.BaseController;
import com.dv.framework.websocket.WebSocketServer;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author HanKang
 * @creat 2023-04-03
 */
@Controller
@RequestMapping("/wms/websocket")
public class WebSocketController extends BaseController
{
    //推送数据接口
    @ResponseBody
    @RequestMapping("/push")
    public Map<String, Object> pushToWeb(String sid, String message) {
        if (message == null) {
            message = "我是消息!";
        }
        Map<String, Object> result = new HashMap<>();
        try {
            WebSocketServer.sendInfo(message, sid);
            result.put("code", 200);
            result.put("msg", "success");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }

}
